﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace MM.Common.Setup
{
    public partial class FrmSelectFromGrid : XtraForm
    {
        public int ChoiceRow = -1;
        public FrmSelectFromGrid()
        {
            InitializeComponent();
        }

        public FrmSelectFromGrid(DataTable dt, string[] column_name, int[] column_width, string title)
        {
            this.InitializeComponent();
            this.Text = title;
            this.gridControl1.DataSource = dt;
            for (int i = 0; i < this.gv1.Columns.Count; i++)
            {
                this.gv1.Columns[i].Caption = column_name[i];
                if (column_width[i] == 0)
                {
                    this.gv1.Columns[i].Visible = false;
                }
                else
                {
                    this.gv1.Columns[i].Width = column_width[i];
                }
                this.gv1.Columns[i].OptionsColumn.ReadOnly = true;
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            base.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.gv1.FocusedRowHandle >= 0)
            {
                this.ChoiceRow = this.gv1.GetDataSourceRowIndex(this.gv1.FocusedRowHandle);
                base.DialogResult = DialogResult.OK;
                base.Close();
            }
        }
    }
}
